﻿#ifndef TIMGWIDGET_H
#define TIMGWIDGET_H

#include <QGraphicsItem>
#include <QMainWindow>
#include <QObject>
#include <QWidget>

// class TImgWidget : public QGraphicsItem
// {
// public:
//     TImgWidget();
// };

#include <QWidget>
#include <QtGui>
#include <QPixmap>
#include <QPainter>
#include <QRectF>
#include <QMouseEvent>
#include <QPointF>
#include <QDragEnterEvent>
#include <QGraphicsSceneWheelEvent>
#include <QGraphicsItem>

enum Enum_ZoomState{
    NO_STATE,
    RESET,
    ZOOM_IN,
    ZOOM_OUT
};
// class ImageWidget :public QObject, QGraphicsItem
class TImgWidget :public QGraphicsItem
{
    //Q_OBJECT
public:
    TImgWidget(QPixmap *pixmap);
    QRectF  boundingRect() const;
    void    paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    void    wheelEvent(QGraphicsSceneWheelEvent *event);
    void    ResetItemPos();
    void    mousePressEvent(QGraphicsSceneMouseEvent *event);
    void    mouseMoveEvent(QGraphicsSceneMouseEvent *event);
    void    mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
    qreal   getScaleValue() const;

    /**
     * @brief 设置图片正常显示的大小
     * @param nwidth
     * @param nheight
     */
    void    setQGraphicsViewWH(int nwidth,int nheight);

    /**
     * @brief 设置图片最小可以缩小的宽高
     * @param width
     * @param height
     */
    void setMinScale(int width, int height);

    void setMax();

    void setMin();

    void setFlippedX(bool flipped);
    bool getFlippedX() const;

    void setFlippedY(bool flipped);
    bool getFlippedY() const;

private:
    qreal       m_scaleValue;
    qreal       m_scaleDafault;
    QPixmap     m_pix;
    int         m_zoomState;
    bool        m_isMove;
    QPointF     m_startPos;

    // 图片缩小的最小值
    qreal       m_minScale;

    bool m_isFlippedX; // 水平翻转标志
    bool m_isFlippedY; // 垂直翻转标志
};

#endif // TIMGWIDGET_H

